(function (){
    var setFormResult = window.setFormResult = function (data) {
        //console.log(data);
        layer.closeAll();
        if(data.status != 10000) {
            layer.alert(data.errmsg, {icon: 5});
        } else {
            layer.confirm('操作成功！', {icon: 6, title:'系统提示', btn: '查看列表'}, function(index){
                location.href = $('#form_update').attr('durl');
                //parent.location.reload(true);
            })/*,function(index){
             location.reload(true); //继续添加
             };*/
        }
    };
    $(function(){
        $('#form_update').on('valid.form', function(e, form){
            layer.load();
            form.submit();
        });

        UE.getEditor('editor');


        $('#add_equipment').click(function(){
            var $text = $('#add_equipmentText').val();
            var html ="";
            html+= '<div class="input-group">' +
                '<input type="text" class="form-control del_equipmentText" name="facilities[]" readonly value="'+$text+'">' +
                '<div class="input-group-addon bg_337ab7 cursor_pointer del_equipment"><i class="fa fa-trash-o"></i> 删除</div>' +
                '</div>';
            var $delText = $('.del_equipmentText').length;

            if($text) {
                if( $delText > 2) {
                    layer.msg('最多只能添加三个',{icon: 2});
                } else if($('.del_equipmentText').last().val() == $text) {
                    layer.msg('不能重复添加',{icon: 2});
                }
                else {
                    $('#delBox').append(html);
                }

            }

            $('.del_equipment').click(function(){
                 $(this).parent().remove();
            })
        })


    });
}());

